import javax.swing.JOptionPane;

public class Ejercicio1 {

	public static void main(String[] args) {

		int N = -1;
		boolean ok;
		
		do {

			do {
				try {
					ok = true;
					N = Integer.parseInt(JOptionPane.showInputDialog("ingrese cantidad de rondas"));

					if (N < 0) {
						JOptionPane.showMessageDialog(null,
								"Caracter invalido, intente nuevamente",
								"ERROR", JOptionPane.ERROR_MESSAGE);
						ok = false;
					}
				} catch (Exception e) {
					JOptionPane.showMessageDialog(null,
							"Caracter invalido, intente nuevamente", "ERROR",
							JOptionPane.ERROR_MESSAGE);
					ok = false;
				}
			} while (ok == false);

			if (N != 0) {
				int x = 0, y = 0;
				
				String Ri= "";
				String[] Riarray = new String[N];
				
				
				
				do{
					ok = true;
					Ri = JOptionPane.showInputDialog("ingrese resultados (0,1)");
					Riarray = Ri.trim().split(" ");
					
					if (Riarray.length!=N){
						ok = false;
					}
		
						for(int j = 0; j< Riarray.length; j++){
							if (Riarray[j].equals("0") || Riarray[j].equals("1")){
							}else{
								ok=false;
							}
						}
						
					if(ok==false){
						JOptionPane.showMessageDialog(null,
								"Caracter invalido, intente nuevamente", "ERROR",JOptionPane.ERROR_MESSAGE);
					}
	
				}while(ok==false);
				

				
				for (int i = 0; i < N; i++) {

					if (Riarray[i].equals("0")) {
						x += 1;
					} else if (Riarray[i].equals("1")) {
						y += 1;
					}
				}
				System.out.println("Mary won " + x + " and Jhon won " + y + " times");
				
			}
		} while (N != 0);
	}
}